<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>防抖</title>
</head>

<body>
  <button id="btndebounce">点击防抖</button>
  <script>
    function debounce(fn, delay) {
      let timer = null;
      return function () {
        if (timer) {
          clearTimeout(timer)
        }
        timer = setTimeout(fn, delay);
      }
    }
    function handle() {
      console.log("执行了");
    }
    const btndebunce = document.getElementById("btndebounce");
    btndebunce.addEventListener("click", debounce(handle, 5000))
  </script>
</body>

</html>